import type { RouteMeta } from 'vue-router';
import { ButtonItem } from "./button";
import { defHttp } from '/@/utils/http/axios';

enum Api {
  Crud = '/menu',
  Table = '/menu/table',
  List = '/menu/list',
  OwnList = '/menu/ownList',
}

/**
 * @description: Get user menu based on id
 */

export const getTableData = (params:any) => defHttp.get<RouteItem[]>({ url: Api.Table, params: params });

export const getListData = (params?: any) => defHttp.get<RouteItem[]>({ url: Api.List, params });

export const create = (params: any) => defHttp.post({url: Api.Crud, params});

export const update = (params: any) => defHttp.put({url: Api.Crud, params});

export const deletes = (params: number[]) => defHttp.delete({url: Api.Crud, data: params});

export const getMenuOwnList = () => defHttp.get<MenuOwnList>({ url: Api.OwnList });

//
export interface RouteItem {
  ID: number;
  path: string;
  component: any;
  meta: RouteMeta;
  name?: string;
  alias?: string | string[];
  redirect?: string;
  caseSensitive?: boolean;
  children?: RouteItem[];
}

export interface MenuOwnList {
  menuList: RouteItem[];
  buttonList: ButtonItem[];
}